package com.movie.controller;
import com.movie.model.auto.Feedback;
import com.movie.model.auto.FeedbackAccount;
import com.movie.service.impl.FeedbackServiceImpl;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/feedback")
@CrossOrigin
public class FeedbackController {

    @Resource
    private FeedbackServiceImpl feedbackService;
    /*查询反馈*/
    @GetMapping("/getFeedback")
    public List<FeedbackAccount> getFeedback(){
        return feedbackService.SelectAll();
    }

    /*通过id查询反馈*/
    @GetMapping("/getFeedbackById/{id}")
    public Feedback getFeedbackById(@PathVariable("id") int id) {
        return feedbackService.getById(id);
    }

    /*修改反馈*/
    @PostMapping("/updateFeedback")
    public void updateFeedback(@RequestBody Feedback feedback){
        feedbackService.updateById(feedback);
    }

    /*添加反馈*/
    @PostMapping("/setFeedback")
    public void setFeedback(@RequestBody Feedback feedback){
        feedbackService.save(feedback);
    }

    /*删除反馈*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return feedbackService.removeById(id);
    }

    /*批量删除反馈*/
    @PostMapping("/deletedAllById")
    public boolean deletedAllById(@RequestBody int[] delarr){
        for (int id : delarr) {
            System.out.println(id);
            feedbackService.removeById(id);
        }
        return true;
    }

    /*模糊查询反馈数据*/
    @PostMapping("/selectFeedback/{input}")
    public List<FeedbackAccount> selectUser(@PathVariable("input") String value){
        return feedbackService.SelectByName(value);
    }


    /*根据用户id查询所有的反馈*/
    @GetMapping("/SelectById/{id}")
    public List<FeedbackAccount> SelectById(@PathVariable("id")int id){
        return feedbackService.SelectById(id);
    }
}
